package com.dingding.baseservice.email.impl;

import java.util.Map;

import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import com.dingding.baseservice.email.ITemplateEmail;

import freemarker.template.Template;

/**
 * 
 * @ClassName: ITemplateEmail 
 * @Description: 获取邮件模板实现
 * @author CHEHAUNBO 
 * @date 2016年1月27日 下午4:13:22
 * 
 */
public class TemplateEmail implements ITemplateEmail {

	private FreeMarkerConfigurer freeMarkerConfigurer = null;// FreeMarker的技术类

	/**
	 * 
	 * @Title: getMailText 
	 * @Description: 获取邮件发送模板
	 * @param root 模板张要添加的参数
	 * @param templateName 模板文件名称
	 * @return String 拼装好的邮件模板
	 * @author CHEHAUNBO
	 * @Override
	 * 
	 */
	public String getMailText(Map<String, Object> root, String templateName) {

		String htmlText = "";
		try {
			// 通过指定模板名获取FreeMarker模板实例
			Template tpl = freeMarkerConfigurer.getConfiguration().getTemplate(templateName);
			htmlText = FreeMarkerTemplateUtils.processTemplateIntoString(tpl, root);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return htmlText;
	}

	public FreeMarkerConfigurer getFreeMarkerConfigurer() {
		return freeMarkerConfigurer;
	}

	public void setFreeMarkerConfigurer(FreeMarkerConfigurer freeMarkerConfigurer) {
		this.freeMarkerConfigurer = freeMarkerConfigurer;
	}

}
